using System;
using System.Collections.Generic;
using System.Text;
using Microsoft.Practices.EnterpriseLibrary.Logging.TraceListeners;
using Microsoft.Practices.EnterpriseLibrary.Logging.Configuration;
using Microsoft.Practices.EnterpriseLibrary.Common.Configuration;
using System.Diagnostics;
using Microsoft.Practices.EnterpriseLibrary.Logging;

namespace Jbe.TestSuite.LogViewer
{
    /// <summary>
    /// Trace listener that saves LogEntry objects in the memory.
    /// </summary>
    [ConfigurationElementType(typeof(CustomTraceListenerData))]
    public class LogViewerTraceListener : CustomTraceListener
    {
        public override void TraceData(TraceEventCache eventCache, string source, TraceEventType eventType, int id, object data)
        {
            if (data is LogEntry) { LogRecorder.Log((LogEntry)data); }
            else { LogRecorder.Log(data); }
        }

        public override void Write(string message)
        {
            LogRecorder.Log(message);
        }

        public override void WriteLine(string message)
        {
            LogRecorder.Log(message);
        }
    }
}
